-
Notifications
You must be signed in to change notification settings - Fork 215
Makes USB examples in Tier 1 BSPs safe and suppresses compiler warnings #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kyp44
wants to merge
10
commits into
atsamd-rs:master
Choose a base branch
from
kyp44:tier1-bsp-usb-examples
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
I had a look at this, overall quite happy with things, However, I think the In some other projects I have done with USB, I have gotten around the static mut like so Incomplete example: pub static USB_BUS_ALLOC: StaticCell<UsbBusAllocator<UsbBus>> = StaticCell::new();
// Data to be accessed whenever an ISR occurs on USB
pub struct UsbIsrInfo<'a> {
pub dev: UsbDevice<'a, UsbBus>,
pub class: SomeClassLikeSerial<'a, UsbBus>,
}
pub static USB: Mutex<RefCell<Option<UsbIsrInfo<'static>>>> = Mutex::new(RefCell::new(None));
#[inline(always)]
pub fn with_cs_mutex<R, T, F: FnOnce(&CriticalSection, &mut T) -> R>(
m: &Mutex<RefCell<Option<T>>>,
f: F,
) -> Option<R> {
free(|cs| m.borrow(cs).borrow_mut().as_mut().map(|x| f(cs, x)))
}
/// Example usage for ISR:
#[interrupt]
fn USB_OTHER() {
poll_usb();
}
#[interrupt]
fn USB_TRCPT0() {
poll_usb();
}
#[interrupt]
fn USB_TRCPT1() {
poll_usb();
}
fn poll_usb() {
free(|cs| {
if let Some(inf) = USB.borrow(cs).borrow_mut().as_mut() {
if inf.dev.poll(&mut [&mut inf.can_usb]) {
inf.class.poll(cs);
}
}
});
}
|
e37b925 to
98d8a06
Compare
…HAL to support refactoring the `feather_m0/adalogger` example.
* For the `adalogger` example, fixes a compiler error by upgrading the `embedded-sdmmc` dependency and migrating to the new API. * Fixes a minor compiler error in the `adc` example when the `use_semihosting` feature is enabled. * Fixes a minor compiler warning in the `async_adc` example.
* Fixes a minor compiler warning in the `adc` example. * Fixes a minor compiler warning in the `async_adc` example.
* Renames `usb_echo` to `usb_echo_basic` and suppresses the `static mut` warnings. * Adds the `usb_echo_rtic` example showing how using USB is easier with RTIC.
…esses the `static mut` warnings.
…atics to use `OnceCell` and suppressing the `static mut` warnings: * `nvm_dsu` * `pukcc_test` * `smart_eeprom` * `usb_echo`
…mut` warnings: * `adalogger` * `clock` * `usb_echo`
…he `static mut` warnings.
98d8a06 to
4201e2b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
NOTE: Marking as draft because this depends on a merge of PR #935.
A number of Tier 1 BSP examples that use USB as a serial device emit compiler warnings related to the necessary use of
static mut. Additionally, some are not used in a safe way.This updates these examples to suppress the warnings and make things safe by accessing the USB device in the main program (i.e. not in the USB polling interrupt) only in crticial sections that disable applicable USB interrupts.
The usability issue with USB in embedded applications is a known issue, and the best solution for these examples was discussed in Matrix.
See the commit log for details about which BSP examples were changed, and not that each BSP crate was changed in a separate commit per the guideline.
Checklist
#[allow]certain lints where reasonable, but ideally justify those with a short comment.